package cn.cs.yangtai.entity.vo;

import lombok.Data;

@Data
public class ResponsePojo<T> {
    private T data;//返回数据
    private String msg;//提示信息
    private Integer code;//成功为1，失败为2

    //通过构造方法设置默认值
    private ResponsePojo(T t){
        this.data = t;
        this.code = 1;
        this.msg = "success";
    }
    //通过构造方法设置自定义值
    private ResponsePojo(T t,String msg,Integer code){
        this.data = t;
        this.msg = msg;
        this.code = code;
    }
    //返回成功
    public static <T> ResponsePojo<T> success(T t){
        return new ResponsePojo(t);
    }
    public static <T> ResponsePojo<T> success(T t,String msg){
        return new ResponsePojo(t,msg,1);
    }
    //返回失败
    public static <T> ResponsePojo<T> fail(T t,String msg){
        return new ResponsePojo(t,msg,2);
    }
}